<?php
	class TableTool extends Table{
		# DB 셀렉트 결과를 넣으면 테이블로 리턴.
		#
		#	$tbl = new Table;
		#	echo $tbl->array_to_table($article['res']);
		public function array_to_table($arr) {
			$ret .= $this->table_start();
				$ret .= $this->tr_start();
				foreach($arr as $key=>$val){
					foreach($val as $k=>$v){
						$ret .= $this->th_start();
						$ret .= $k;
						$ret .= $this->th_end();
					}
					break;
				}
				$ret .= $this->tr_end();
				foreach($arr as $key=>$val){
					$ret .= $this->tr_start();
						foreach($arr[$key] as $key=>$val){
							$ret .= $this->td_start();
							$ret .= $val;
							$ret .= $this->td_end();
						}
					$ret .= $this->tr_end();
				}
			$ret .= $this->table_end();

			return $ret;
		}

		# 다이나믹 콜컬럼 테이블
		#	[?php
		#		$tarr = array(60,120,0,160,100,100);
		#	?]
		#	<table [?=$tbltool->tablewidth($tarr)?] border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse">
		#		[?=$tbltool->colgroup($tarr)?]
		#		<tr>
		#			<th [?=$tbltool->colspan($tarr)?]></th>
		#		</tr>
		#		<tr>
		#			<th>1</th>
		#			<th>2</th>
		#			<th>3</th>
		#			<th>4</th>
		#			<th>5</th>
		#			<th>6</th>
		#		</tr>
		#		<tr>
		#			<th [?=$tbltool->colspan($tarr)?]></th>
		#		</tr>
		#		<tr>
		#			<td>a</td>
		#			<td>b</td>
		#			<td>c</td>
		#			<td>d</td>
		#			<td>e</td>
		#			<td>f</td>
		#		</tr>
		#	</table>
		public function colgroup($tarr) {
			$ret = "<colgroup>";
				foreach($tarr as $row=>$val):
					if($val == 0):
						$ret .= "<col width=\"*\" />";
					else:
						$ret .="<col width=\"{$val}px\" />";
					endif;
				endforeach;
			$ret .= "</colgroup>";
			return $ret;
		}

		public function colspan($tarr){
			 $ret = sprintf("colspan=\"%s\"", sizeof($tarr));
			 return $ret;
		}

		public function tablewidth($tarr){
			$ret = sprintf("width=\"%s\"", array_sum($tarr));
			 return $ret;
		}
	}